<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>PyQt5安装和入门 | To Share</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/share/favicon.ico">
    <meta name="description" content="分享风雨，享受阳光">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/share/assets/css/0.styles.d7affcea.css" as="style"><link rel="preload" href="/share/assets/js/app.706684de.js" as="script"><link rel="preload" href="/share/assets/js/3.4685d505.js" as="script"><link rel="preload" href="/share/assets/js/1.b12738fb.js" as="script"><link rel="preload" href="/share/assets/js/43.5136999f.js" as="script"><link rel="preload" href="/share/assets/js/9.4e81f08e.js" as="script"><link rel="prefetch" href="/share/assets/js/10.9e95ce7b.js"><link rel="prefetch" href="/share/assets/js/11.e99410dc.js"><link rel="prefetch" href="/share/assets/js/12.e9afe07c.js"><link rel="prefetch" href="/share/assets/js/13.078dd281.js"><link rel="prefetch" href="/share/assets/js/14.6575b8f0.js"><link rel="prefetch" href="/share/assets/js/15.d942bb10.js"><link rel="prefetch" href="/share/assets/js/16.fd8cc40c.js"><link rel="prefetch" href="/share/assets/js/17.f1b1f2c6.js"><link rel="prefetch" href="/share/assets/js/18.b312ce79.js"><link rel="prefetch" href="/share/assets/js/19.a99d170f.js"><link rel="prefetch" href="/share/assets/js/20.cda2b911.js"><link rel="prefetch" href="/share/assets/js/21.d6062607.js"><link rel="prefetch" href="/share/assets/js/22.5a50eee4.js"><link rel="prefetch" href="/share/assets/js/23.be601eed.js"><link rel="prefetch" href="/share/assets/js/24.3d0b9811.js"><link rel="prefetch" href="/share/assets/js/25.c1c35d96.js"><link rel="prefetch" href="/share/assets/js/26.9a8b03ff.js"><link rel="prefetch" href="/share/assets/js/27.6c302f3e.js"><link rel="prefetch" href="/share/assets/js/28.5eb55960.js"><link rel="prefetch" href="/share/assets/js/29.8297842b.js"><link rel="prefetch" href="/share/assets/js/30.b453256b.js"><link rel="prefetch" href="/share/assets/js/31.6ce2e46f.js"><link rel="prefetch" href="/share/assets/js/32.cf3906ab.js"><link rel="prefetch" href="/share/assets/js/33.83680f76.js"><link rel="prefetch" href="/share/assets/js/34.dada508c.js"><link rel="prefetch" href="/share/assets/js/35.11a36f17.js"><link rel="prefetch" href="/share/assets/js/36.fc43ef74.js"><link rel="prefetch" href="/share/assets/js/37.af715eba.js"><link rel="prefetch" href="/share/assets/js/38.7ba3e6e1.js"><link rel="prefetch" href="/share/assets/js/39.cd1c9d09.js"><link rel="prefetch" href="/share/assets/js/4.c1f99423.js"><link rel="prefetch" href="/share/assets/js/40.8df0c044.js"><link rel="prefetch" href="/share/assets/js/41.e643a418.js"><link rel="prefetch" href="/share/assets/js/42.d809cd4f.js"><link rel="prefetch" href="/share/assets/js/44.315a82bf.js"><link rel="prefetch" href="/share/assets/js/45.a4b04306.js"><link rel="prefetch" href="/share/assets/js/46.2e8ec77e.js"><link rel="prefetch" href="/share/assets/js/47.d6bde2ca.js"><link rel="prefetch" href="/share/assets/js/48.e8e85c15.js"><link rel="prefetch" href="/share/assets/js/49.fce2ff19.js"><link rel="prefetch" href="/share/assets/js/5.599dfd12.js"><link rel="prefetch" href="/share/assets/js/50.3918e713.js"><link rel="prefetch" href="/share/assets/js/51.c5ddf50e.js"><link rel="prefetch" href="/share/assets/js/52.b6653f73.js"><link rel="prefetch" href="/share/assets/js/53.c0420367.js"><link rel="prefetch" href="/share/assets/js/54.0f64522f.js"><link rel="prefetch" href="/share/assets/js/55.1f9ce6fb.js"><link rel="prefetch" href="/share/assets/js/56.0a2fc30f.js"><link rel="prefetch" href="/share/assets/js/57.3b81efcb.js"><link rel="prefetch" href="/share/assets/js/58.c617dcad.js"><link rel="prefetch" href="/share/assets/js/59.5239e9d4.js"><link rel="prefetch" href="/share/assets/js/6.4e5676a9.js"><link rel="prefetch" href="/share/assets/js/60.b614d70b.js"><link rel="prefetch" href="/share/assets/js/61.f45be005.js"><link rel="prefetch" href="/share/assets/js/62.52121455.js"><link rel="prefetch" href="/share/assets/js/63.9f699597.js"><link rel="prefetch" href="/share/assets/js/64.01c4bf37.js"><link rel="prefetch" href="/share/assets/js/65.0f31fd4b.js"><link rel="prefetch" href="/share/assets/js/66.55dbbe80.js"><link rel="prefetch" href="/share/assets/js/67.fd9ba6df.js"><link rel="prefetch" href="/share/assets/js/68.c6c9e158.js"><link rel="prefetch" href="/share/assets/js/69.91757641.js"><link rel="prefetch" href="/share/assets/js/7.b8928c33.js"><link rel="prefetch" href="/share/assets/js/70.12f0a894.js"><link rel="prefetch" href="/share/assets/js/71.88c99794.js"><link rel="prefetch" href="/share/assets/js/72.e1d99c59.js"><link rel="prefetch" href="/share/assets/js/73.aee6f06a.js"><link rel="prefetch" href="/share/assets/js/74.b47532b0.js"><link rel="prefetch" href="/share/assets/js/75.1f1ab66e.js"><link rel="prefetch" href="/share/assets/js/8.56deb6eb.js">
    <link rel="stylesheet" href="/share/assets/css/0.styles.d7affcea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-130b300a><div data-v-130b300a><div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-130b300a data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>To Share</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>分享风雨，享受阳光</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-130b300a><header class="navbar" data-v-130b300a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/share/" class="home-link router-link-active"><!----> <span class="site-name">To Share</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-130b300a></div> <aside class="sidebar" data-v-130b300a><div class="personal-info-wrapper" data-v-39576ba9 data-v-130b300a><img src="/share/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <!----> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>63</h3> <h6 data-v-39576ba9>文章</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>51</h3> <h6 data-v-39576ba9>标签</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/share/docs/gui/" aria-current="page" class="active sidebar-link">PyQt5安装和入门</a></li><li><a href="/share/docs/gui/QObject.html" class="sidebar-link">QObject基类</a></li><li><a href="/share/docs/gui/one.html" class="sidebar-link">PySide2介绍</a></li><li><a href="/share/docs/gui/designer.html" class="sidebar-link">QT设计师</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>PyQt5安装和入门</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div data-v-130b300a><main class="page"><section><div class="page-title"><h1 class="title">PyQt5安装和入门</h1> <div data-v-f875f3fc><!----> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>2022/5/20</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>python</span><span class="tag-item" data-v-f875f3fc>pyqt</span><span class="tag-item" data-v-f875f3fc>gui</span></i></div></div> <div class="theme-reco-content content__default"><div id="boxx" data-v-f4ca0dac><div data-v-f4ca0dac><p v-if="true" class="custom-block-title" data-v-f4ca0dac></p> <p v-if="true" data-v-f4ca0dac></p></div></div> <p><a href="https://www.riverbankcomputing.com/static/Docs/PyQt5/index.html" target="_blank" rel="noopener noreferrer">PyQt5文档<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="http://www.bl186.net/pyqt5/" target="_blank" rel="noopener noreferrer">博主村长<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="http://www.pyqt5.cn/" target="_blank" rel="noopener noreferrer">PyQt5中文网<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="安装pyqt5和pyside2"><a href="#安装pyqt5和pyside2" class="header-anchor">#</a> 安装PyQt5和PySide2</h2> <p>创建一个虚拟环境, 安装PyQt5和PySide2</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>pip <span class="token function">install</span> PyQt5
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-shell line-numbers-mode"><pre class="language-shell"><code>pip <span class="token function">install</span> PySide2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ol><li>pyqt5做为Python的一个模块，是最强大的GUI库之一。它有620多个类和6000个函数和方法。这是一个跨平台的工具包，它可以运行在所有主要的操作系统，包括UNIX，Windows，Mac
OS。pyqt5是双重许可。开发者可以在GPL和商业许可之间进行选择。</li> <li>PySide2可视化编辑界面, 能实现所见即所得。</li></ol> <h2 id="常用代码解读"><a href="#常用代码解读" class="header-anchor">#</a> 常用代码解读</h2> <p>PyQt5的代码, 被我们经常使用到的, 都非常统一</p> <div class="language-python line-numbers-mode"><pre class="language-python"><code><span class="token keyword">from</span> PyQt5<span class="token punctuation">.</span>Qt <span class="token keyword">import</span> QApplication<span class="token punctuation">,</span> QWidget<span class="token punctuation">,</span> QPushButton<span class="token punctuation">,</span> QLabel
<span class="token keyword">import</span> sys

<span class="token comment"># 创建一个应用程序, sys.argv用来接收命令行传递的参数</span>
app <span class="token operator">=</span> QApplication<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span>

window <span class="token operator">=</span> QWidget<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 创建一个window</span>
window<span class="token punctuation">.</span>setWindowTitle<span class="token punctuation">(</span><span class="token string">&quot;我是软件名称&quot;</span><span class="token punctuation">)</span>  <span class="token comment"># 给这个窗口一个标记名称</span>
window<span class="token punctuation">.</span>resize<span class="token punctuation">(</span><span class="token number">600</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span>  <span class="token comment"># 设置窗口的大小, 不包含软件名称那一行的大小</span>

btn <span class="token operator">=</span> QPushButton<span class="token punctuation">(</span>window<span class="token punctuation">)</span>  <span class="token comment"># window界面里面创建一个按钮</span>
btn<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">&quot;我是一个按钮&quot;</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的呢内容</span>
btn<span class="token punctuation">.</span>resize<span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的尺寸</span>
btn<span class="token punctuation">.</span>move<span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的位置, 指的是按钮左上角到window的左上角的位置</span>
btn<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:16px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>

label <span class="token operator">=</span> QLabel<span class="token punctuation">(</span>window<span class="token punctuation">)</span>  <span class="token comment"># 创建了一个标签</span>
label<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">'我是创建的标签'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置标签内容</span>
label<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:16px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>
window<span class="token punctuation">.</span>show<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 显示window视窗</span>

<span class="token comment"># 检测程序代码退出原因,app.exec_()是一个消息循环程序,没有这个程序就会闪退,有了这个, 程序会一直存在</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span>app<span class="token punctuation">.</span>exec_<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br></div></div><h2 id="配置面向对象开发模板"><a href="#配置面向对象开发模板" class="header-anchor">#</a> 配置面向对象开发模板</h2> <blockquote><p>python是面向对象的开发语言, 开发项目的时候, 我们应该把代码包装的成对象或者类, 方便后面后面使用的时候多次调用。</p></blockquote> <div class="demo-wrap"><div class="demo-nav"><i class="demo-nav-btn"><svg t="1572515960134" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1097" width="20" height="20" class="icon"><path d="M888 64H136q-30.016 0-51.008 20.992T64 136v752.992q0 28.992 20.992 50.496t51.008 21.504h752.992q28.992 0 50.496-21.504t21.504-50.496V136q0-30.016-21.504-51.008T888 64zM228.992 548.992q-15.008 0-25.504-10.496t-10.496-25.504 10.016-26.016l115.008-115.008-115.008-116.992q-10.016-11.008-10.016-25.504t10.496-24.992 25.504-10.496 24.992 10.016l140.992 142.016q10.016 11.008 10.016 26.016t-11.008 24.992l-140 140.992q-10.016 11.008-24.992 11.008z m389.024 0l-199.008-0.992q-15.008 0-25.504-10.496T383.008 512t10.496-25.504 25.504-10.496l199.008 0.992q15.008 0 25.504 10.496t10.496 25.504-11.008 25.504-24.992 10.496z" p-id="1098"></path></svg></i> <i class="demo-icon-arrow active"><svg t="1572587847226" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3297" width="16" height="16" class="icon"><path d="M830.687738 603.071182c0 9.614985-3.933589 17.949814-11.799744 25.007557-7.867178 7.05672-17.222243 10.56052-28.065196 10.512425L232.716714 638.591163c-10.789741 0-20.144806-3.5038-28.064172-10.512425-7.919367-7.009647-11.852956-15.344476-11.799744-25.007557 0.053212-9.660011 3.986801-17.996886 11.799744-25.00551l279.05253-248.641917c7.867178-7.009647 17.22122-10.513448 28.065196-10.513448 10.842952 0 20.196994 3.504824 28.064172 10.513448l279.05253 248.641917C826.754149 585.074296 830.687738 593.411171 830.687738 603.071182z" p-id="3298"></path></svg></i></div> <div class="demo-code"><div class="demo-code-nav"><button class="demo-code-btn active">Gui.py类</button><button class="demo-code-btn">Demo调用</button></div> <div class="demo-code-content"><div class="demo-code-item"><div class="language-py line-numbers-mode"><pre class="language-py"><code><span class="token keyword">from</span> PyQt5<span class="token punctuation">.</span>Qt <span class="token keyword">import</span> QWidget<span class="token punctuation">,</span> QPushButton<span class="token punctuation">,</span> QLabel


<span class="token keyword">class</span> <span class="token class-name">Window</span><span class="token punctuation">(</span>QWidget<span class="token punctuation">)</span><span class="token punctuation">:</span>  <span class="token comment"># Window类继承于QWidget</span>
    <span class="token triple-quoted-string string">&quot;&quot;&quot;
    PyQt类
    &quot;&quot;&quot;</span>

    <span class="token keyword">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token builtin">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>__init__<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 调用父类QWidget中的init方法</span>
        self<span class="token punctuation">.</span>setWindowTitle<span class="token punctuation">(</span><span class="token string">&quot;我是软件名称&quot;</span><span class="token punctuation">)</span>  <span class="token comment"># 给这个窗口一个标记名称</span>
        self<span class="token punctuation">.</span>resize<span class="token punctuation">(</span><span class="token number">600</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span>  <span class="token comment"># 设置窗口的大小, 不包含软件名称那一行的大小</span>
        self<span class="token punctuation">.</span>func_list<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 调用自身的方法</span>

    <span class="token keyword">def</span> <span class="token function">func_list</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>  <span class="token comment"># 这里是程序调用的函数, 这样代码就比较整洁清晰了</span>
        self<span class="token punctuation">.</span>func<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>func1<span class="token punctuation">(</span><span class="token punctuation">)</span>
        self<span class="token punctuation">.</span>func2<span class="token punctuation">(</span><span class="token punctuation">)</span>

    <span class="token keyword">def</span> <span class="token function">func</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token triple-quoted-string string">&quot;&quot;&quot;
        增加一个按钮
        &quot;&quot;&quot;</span>
        btn <span class="token operator">=</span> QPushButton<span class="token punctuation">(</span>self<span class="token punctuation">)</span>  <span class="token comment"># window界面里面创建一个按钮</span>
        btn<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">&quot;我是按钮内容&quot;</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的呢内容</span>
        btn<span class="token punctuation">.</span>resize<span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的尺寸</span>
        btn<span class="token punctuation">.</span>move<span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的位置, 指的是按钮左上角到window的左上角的位置</span>
        btn<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:20px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>

    <span class="token keyword">def</span> <span class="token function">func1</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token triple-quoted-string string">&quot;&quot;&quot;
        增加一个标签
        &quot;&quot;&quot;</span>
        label <span class="token operator">=</span> QLabel<span class="token punctuation">(</span>self<span class="token punctuation">)</span>  <span class="token comment"># 创建了一个标签</span>
        label<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">'我是标签内容'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置标签内容</span>
        label<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:16px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>

    <span class="token keyword">def</span> <span class="token function">func2</span><span class="token punctuation">(</span>self<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token triple-quoted-string string">&quot;&quot;&quot;
        增加一个标签
        &quot;&quot;&quot;</span>
        label <span class="token operator">=</span> QLabel<span class="token punctuation">(</span>self<span class="token punctuation">)</span>  <span class="token comment"># 创建了一个标签</span>
        label<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">'我是标签内容'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置标签内容</span>
        label<span class="token punctuation">.</span>move<span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span>  <span class="token comment"># 设置标签位置,指的是按钮左上角到window的左上角的位置</span>
        label<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:16px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br></div></div></div><div class="demo-code-item" style="display:none;"><div class="language-py line-numbers-mode"><pre class="language-py"><code><span class="token keyword">from</span> gui <span class="token keyword">import</span> Window
<span class="token keyword">from</span> PyQt5<span class="token punctuation">.</span>Qt <span class="token keyword">import</span> QApplication<span class="token punctuation">,</span> qApp
<span class="token keyword">import</span> sys

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    app <span class="token operator">=</span> QApplication<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span>  <span class="token comment"># 创建一个应用程序对象</span>
    <span class="token comment"># sys.argv可以接收用户命令行启动时所输入的参数，根据参数执行不同程序</span>
    <span class="token comment"># qApp 为全局对象</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>app<span class="token punctuation">.</span>arguments<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>qApp<span class="token punctuation">.</span>arguments<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token comment"># 以上三个输出结果是一样的</span>
    window <span class="token operator">=</span> Window<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 调用window类,操作空间</span>

    window<span class="token punctuation">.</span>show<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 显示window视窗</span>
    sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span>app<span class="token punctuation">.</span>exec_<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment"># 0是正常退出</span>
    <span class="token comment"># app.exec_()  进行消息循环</span>
    <span class="token comment"># sys.exit()   检测退出原因</span></code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div></div> <i class="demo-code-content-copy"><svg t="1572585974849" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1695" width="20" height="20" class="icon" style="fill:#fff;"><path d="M866.461538 39.384615H354.461538c-43.323077 0-78.769231 35.446154-78.76923 78.769231v39.384616h472.615384c43.323077 0 78.769231 35.446154 78.769231 78.76923v551.384616h39.384615c43.323077 0 78.769231-35.446154 78.769231-78.769231V118.153846c0-43.323077-35.446154-78.769231-78.769231-78.769231z m-118.153846 275.692308c0-43.323077-35.446154-78.769231-78.76923-78.769231H157.538462c-43.323077 0-78.769231 35.446154-78.769231 78.769231v590.769231c0 43.323077 35.446154 78.769231 78.769231 78.769231h512c43.323077 0 78.769231-35.446154 78.76923-78.769231V315.076923z m-354.461538 137.846154c0 11.815385-7.876923 19.692308-19.692308 19.692308h-157.538461c-11.815385 0-19.692308-7.876923-19.692308-19.692308v-39.384615c0-11.815385 7.876923-19.692308 19.692308-19.692308h157.538461c11.815385 0 19.692308 7.876923 19.692308 19.692308v39.384615z m157.538461 315.076923c0 11.815385-7.876923 19.692308-19.692307 19.692308H216.615385c-11.815385 0-19.692308-7.876923-19.692308-19.692308v-39.384615c0-11.815385 7.876923-19.692308 19.692308-19.692308h315.076923c11.815385 0 19.692308 7.876923 19.692307 19.692308v39.384615z m78.769231-157.538462c0 11.815385-7.876923 19.692308-19.692308 19.692308H216.615385c-11.815385 0-19.692308-7.876923-19.692308-19.692308v-39.384615c0-11.815385 7.876923-19.692308 19.692308-19.692308h393.846153c11.815385 0 19.692308 7.876923 19.692308 19.692308v39.384615z" p-id="1696"></path></svg></i> <!----></div></div> <div class="demo-main"><!----></div></div> <h2 id="编写pyqt5的流程"><a href="#编写pyqt5的流程" class="header-anchor">#</a> 编写PyQt5的流程</h2> <ol><li>创建一个应用程序</li></ol> <div class="language-py line-numbers-mode"><pre class="language-py"><code>app <span class="token operator">=</span> QApplication<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ol start="2"><li>控件操作</li></ol> <div class="language-py line-numbers-mode"><pre class="language-py"><code>btn <span class="token operator">=</span> QPushButton<span class="token punctuation">(</span>self<span class="token punctuation">)</span>  <span class="token comment"># window界面里面创建一个按钮</span>
btn<span class="token punctuation">.</span>setText<span class="token punctuation">(</span><span class="token string">&quot;我是按钮内容&quot;</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的呢内容</span>
btn<span class="token punctuation">.</span>resize<span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的尺寸</span>
btn<span class="token punctuation">.</span>move<span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的位置, 指的是按钮左上角到window的左上角的位置</span>
btn<span class="token punctuation">.</span>setStyleSheet<span class="token punctuation">(</span><span class="token string">'background-color:green;font-size:20px;'</span><span class="token punctuation">)</span>  <span class="token comment"># 设置按钮的背景色和字体尺寸</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ol start="3"><li>执行应用，进入消息循环</li></ol> <div class="language-py line-numbers-mode"><pre class="language-py"><code>window<span class="token punctuation">.</span>show<span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment"># 显示window视窗</span>
sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span>app<span class="token punctuation">.</span>exec_<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment"># 0是正常退出</span>
<span class="token comment"># app.exec_()  进行循环 </span>
<span class="token comment"># sys.exit()   检测退出原因</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2022/5/19 23:24:38</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/share/docs/gui/QObject.html">
            QObject基类
          </a></span></p></div> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/share/docs/gui/#安装pyqt5和pyside2" class="sidebar-link reco-side-安装pyqt5和pyside2" data-v-cb1513f6>安装PyQt5和PySide2</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/gui/#常用代码解读" class="sidebar-link reco-side-常用代码解读" data-v-cb1513f6>常用代码解读</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/gui/#配置面向对象开发模板" class="sidebar-link reco-side-配置面向对象开发模板" data-v-cb1513f6>配置面向对象开发模板</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/gui/#编写pyqt5的流程" class="sidebar-link reco-side-编写pyqt5的流程" data-v-cb1513f6>编写PyQt5的流程</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><!----><div class="kanbanniang" data-v-5775ee02><div class="banniang-container" style="display:;" data-v-5775ee02><div class="messageBox" style="left:68px;bottom:370px;display:none;" data-v-5775ee02>
      欢迎来到我的博客
    </div> <div class="operation" style="right:90px;bottom:40px;display:none;" data-v-5775ee02><i class="kbnfont kbn-ban-home ban-home" data-v-5775ee02></i> <i class="kbnfont kbn-ban-message message" data-v-5775ee02></i> <i class="kbnfont kbn-ban-close close" data-v-5775ee02></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-5775ee02><i class="kbnfont kbn-ban-info info" data-v-5775ee02></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:;" data-v-5775ee02></i></div> <canvas id="banniang" width="260px" height="420" class="live2d" style="right:200px;bottom:20px;opacity:0.4;" data-v-5775ee02></canvas></div> <div class="showBanNiang" style="display:none;" data-v-5775ee02>
    看板娘
  </div></div><canvas id="vuepress-canvas-cursor"></canvas><!----><div class="RibbonAnimation"></div><!----></div></div>
    <script src="/share/assets/js/app.706684de.js" defer></script><script src="/share/assets/js/3.4685d505.js" defer></script><script src="/share/assets/js/1.b12738fb.js" defer></script><script src="/share/assets/js/43.5136999f.js" defer></script><script src="/share/assets/js/9.4e81f08e.js" defer></script>
  </body>
</html>
